home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 May
/
EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso
/
earcd
/
dev
/
obero
/
dialogs.lha
/
oberonv4
/
system1
/
DialogButtons.Mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1995-12-25
|
9KB
|
217 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
StampElems
Alloc
25 Apr 95
Syntax10b.Scn.Fnt
Chicago10.Scn.Fnt
MODULE DialogButtons;
(** extended version Markus Knasm
ller 25.May.94 -
(* includes a change from: Zhukov Victor <VIC@edge.paragraph.com> VIC
now it acts as a button in Windows, when you with mouse button
pressed move mouse out of Button rectangle it pops back and on
releasing does not issue associated action *)
IMPORT DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Input,
Oberon, TextFrames, Texts, Viewers;
CONST ML = 0; MM = 1; MR = 2; W* = 30; H* = 20; grey1 = 12; grey2 = 13; grey3 = 14; black = 15; white = 0;
TYPE
Item* = POINTER TO ItemDesc;
ItemDesc* = RECORD(Dialogs.ObjectDesc)
fnt-: Fonts.Font; (** font that is used to display the name of the button *)
END;
VAR w0: Texts.Writer;
PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
(** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
VAR x: Item;
BEGIN
IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END;
b.Copy^ (dup); x.fnt := b.fnt;
END Copy;
PROCEDURE (b: Item) Draw1 (x, y: INTEGER; pressed: BOOLEAN; f: Display.Frame);
VAR mode, w, h, yh, ox, oy, cx: INTEGER;
BEGIN
b.GetDim (ox, oy, w, h);
IF b.selected THEN mode := Display.invert ELSE mode := Display.paint END;
GraphicUtils.DrawBox (f, pressed, x, y, w, h, mode);
yh := y + (h DIV 2) - ((b.fnt.minY + b.fnt.maxY) DIV 2);
IF h - (yh - y) > b.fnt.maxY THEN
GraphicUtils.DrawString (f, b.name, x + 3, yh, w - 4, b.fnt, mode, GraphicUtils.center, cx)
END
END Draw1;
PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
(** displays the object at (x, y) in frame f *)
BEGIN b.Draw1 (x, y, FALSE, f)
END Draw;
PROCEDURE (b: Item) Print* (x, y: INTEGER);
(** prints the object at printer coordinates (x, y) *)
VAR w, h, ox, oy, yh, cx: INTEGER; fnth: LONGINT;
BEGIN
b.GetPDim (ox, oy, w, h); GraphicUtils.PrintBox (x, y, w, h);
fnth := ((b.fnt.maxY - b.fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
yh := y + (h DIV 2) - SHORT (fnth);
IF h - (yh - y) > ((b.fnt.maxY * SHORT (Dialogs.dUnit)) DIV Dialogs.pUnit) THEN
GraphicUtils.PrintString (b.name, x + 3, yh, w - 4, b.fnt, GraphicUtils.center, cx)
END
END Print;
PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel; x0, y0: INTEGER);
VAR bx, by, bw, bh: INTEGER; keysum: SET; t: Texts.Text; fPressed: BOOLEAN;
BEGIN
fPressed := TRUE;
b.GetDim (bx, by, bw, bh);
IF (keys = {ML}) OR (keys = {MM}) OR (keys = {MR}) THEN
Oberon.RemoveMarks (x0 + bx, y0 + by, bw, bh);
b.Draw1 (x0 + bx, y0 + by, TRUE, f);
keysum := keys;
REPEAT
Input.Mouse(keys, x, y); keysum := keysum + keys;
IF (x < x0 + bx) OR (x > x0 + bx + bw) OR (y < y0 + by) OR (y > y0 + by + bh) THEN
IF fPressed THEN
fPressed := FALSE;
b.Draw1 (x0 + bx, y0 + by, fPressed, f);
END
ELSE
IF ~fPressed THEN
fPressed := TRUE;
b.Draw1 (x0 + bx, y0 + by, fPressed, f);
END
END; (* VIC Jan 11 1995 *)
Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
UNTIL keys = {};
Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
b.Draw1 (x0 + bx, y0 + by, FALSE, f);
IF ((keysum = {ML}) OR (keysum = {MM}) OR (keysum = {MR})) & fPressed THEN
IF b.cmd[0] # 0X THEN
DialogTexts.GetParText (b.par, p, t);
b.CallCmd (f, Viewers.This (x, y), t)
END
END
ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
END
END Track;
PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
(** handles messages which were sent to frame f *)
BEGIN
b.Handle^ (f, m);
WITH f: DialogFrames.Frame DO
WITH m: Oberon.InputMsg DO
IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel, f.X, f.Y + f.H) END
ELSE
END
ELSE
END
END Handle;
PROCEDURE (b: Item) Load* (VAR r: Files.Rider);
(** reads the object from rider r *)
VAR fntname: ARRAY 32 OF CHAR;
BEGIN b.Load^( r); Files.ReadString (r, fntname); b.fnt := Fonts.This (fntname);
END Load;
PROCEDURE (b: Item) Store* (VAR r: Files.Rider);
(** writes the object to rider r *)
BEGIN b.Store^ (r); Files.WriteString (r, b.fnt.name)
END Store;
PROCEDURE (b: Item) SetFont* (fnt: Fonts.Font);
(** sets the font with which the text is shown *)
BEGIN b.fnt := fnt; b.Restore (); IF b.panel # NIL THEN b.panel.MarkMenu END
END SetFont;
PROCEDURE WriteToObjectStr (o: DialogTexts.Item; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
VAR t: Texts.Text;
BEGIN
t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
END WriteToObjectStr;
PROCEDURE (b: Item) Edit*;
(** opens a dialog for editing the properties of the object *)
VAR on: Dialogs.Object; t: Texts.Text; fnt: Fonts.Font;
BEGIN
b.Edit^ ();
on := Dialogs.editPanel.NamedObject ("name"); t := on(DialogTexts.Item).GetText ();
Texts.ChangeLooks (t, 0, t.len, {0}, b.fnt, 0, 0);
END Edit;
PROCEDURE (b: Item) Update* (p: Dialogs.Panel);
(** sets the properties of the object to the values defined in the dialog p opened with Edit *)
VAR o: Dialogs.Object; t: Texts.Text; r: Texts.Reader; ch: CHAR;
BEGIN
o := p.NamedObject ("name"); t := o(DialogTexts.Item).GetText ();
Texts.OpenReader (r, t, 0); Texts.Read (r, ch);
IF (r.fnt # NIL) & (r.fnt # b.fnt) THEN b.SetFont (r.fnt) END;
b.Update^ (p);
END Update;
PROCEDURE Insert*;
(** Insert ([name] [x y w h] | ^ ) inserts a button - item in the panel containing the caret position *)
VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR; r: Texts.Reader; ch: CHAR;
BEGIN
NEW (b);
DialogFrames.GetCaretPosition(p, x, y);
IF (p # NIL) THEN
b.Init; b.fnt := Fonts.This ("Syntax10.Scn.Fnt");
In.Open; Texts.OpenReader (r, Oberon.Par.text, 0); Texts.Read (r, ch);
In.Name (name);
IF ~In.Done THEN
In.Open; In.String (name);
IF ~In.Done THEN COPY ("", name); In.Open ELSE b.fnt := r.fnt END
ELSE b.fnt := r.fnt
END;
b.SetName (name);
In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H
ELSE
IF w < 0 THEN w := W END;
IF h < 0 THEN h := H END
END;
y := GraphicUtils.GetStringLength (name, b.fnt) + 9;
IF y > w THEN x := w; w := y END;
b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE);
IF Dialogs.res = Dialogs.objectWouldOverlap THEN
b.SetDim (x1, y1, y, h, FALSE); p.Insert (b, FALSE)
END
ELSE
Dialogs.res := Dialogs.noPanelSelected
END;
IF Dialogs.res # 0 THEN Dialogs.Error ("DialogButtons") END;
END Insert;
PROCEDURE DeInit;
VAR s: DialogStaticTexts.Item; b: Item; t: DialogTexts.Item;
BEGIN
NEW (Dialogs.deInit);
NEW (s); s.Init; s.SetDim (2, - 30, 35, 20, FALSE);
s.SetString ("Name"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (13, - 57, 19, 20, FALSE);
s.SetString ("X"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (13, - 87, 19, 20, FALSE);
s.SetString ("Y"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (2, - 116, 35, 20, FALSE);
s.SetString ("Cmd"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (122, - 57, 19, 20, FALSE);
s.SetString ("W"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (122, - 87, 19, 20, FALSE);
s.SetString ("H"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (s); s.Init; s.SetDim (2, - 146, 35, 20, FALSE);
s.SetString ("Par"); s.SetFont (Fonts.This ("Syntax10.Scn.Fnt"));
Dialogs.deInit.Insert (s, FALSE);
NEW (b); b.Init; b.SetDim (195, - 72, 36, 21, FALSE); b.SetName ("Do");
b.SetFont (Fonts.This ("Syntax10.Scn.Fnt")); b.SetCmd ("Dialog.Do");
Dialogs.deInit.Insert (b, FALSE);
NEW (t); t.Init; t.SetDim (38, - 30, 144, 19, FALSE); t.SetName ("name");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (38, - 59, 40, 19, FALSE); t.SetName ("x");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (38, - 86, 40, 19, FALSE); t.SetName ("y");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (38, - 116, 195, 19, FALSE); t.SetName ("cmd");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (142, - 59, 40, 19, FALSE); t.SetName ("w");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (142, - 86, 40, 19, FALSE); t.SetName ("h");
Dialogs.deInit.Insert (t, FALSE);
NEW (t); t.Init; t.SetDim (38, - 146, 195, 19, FALSE); t.SetName ("par");
Dialogs.deInit.Insert (t, FALSE)
END DeInit;
BEGIN Texts.OpenWriter (w0); DeInit
END DialogButtons.